<?php
namespace app\home\controller;
use app\common\controller\Homebase;

// +----------------------------------------------------------------------
// | VenusCMF
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2099
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 水蕃茄 <lzhf237@126.com>
// +----------------------------------------------------------------------

/*
** 
*/

class Api extends Homebase {
	
	// 优先加载
	public function  _initialize() {
		parent::_initialize();
		
	}
	
	public function getImgs() {
		$id = input('param.id/d');
		$lists = \think\Db::name('slide') -> where('id',$id) -> order('id desc') -> find();
		return $lists['faceimg']; 
	}
	public function insertImgs() {
		$inputs = input('post.');
		$inputs['faceimg'] = json_encode($this->upload_img_zxf());
		if(\think\Db::name('slide') -> insert($inputs)){
			$this -> success('操作成功');
		}
		
		$this -> error('操作失败或没有数据可更新');
	}
	/*
	** 20190409 zhuxuefei上传图片
	*/
	public function upload_img_zxf($saveArrRoot = 'file', $savepath = 'article') {
		
		$files = request() -> file('img');
		$config = array(
					'size' 	=> 3145728,
					'ext' 	=> 'jpg,gif,png,jpeg,bmp'
				);
		
		$savePath = ROOT_PATH . 'public' . DS . 'uploads/' . $savepath;
		
		if($files){
			foreach ($files as $key=>$file) {
				$info = $file -> validate($config) -> move($savePath);
				if($info){
					$savename = $info -> getSaveName();
					// 获取图片路径
					$data[$key]['url'] = '/uploads/' . $savepath . '/' . str_replace('\\','/',$savename);
				}
			}
			return $data;
		}
		
	}
}
